﻿using System;
using System.Linq;
using System.Web.Mvc;
using VedranKrizicPortfolio.Models;

namespace VedranKrizicPortfolio.Controllers
{
	public class PortfolioController : Controller
	{
		private readonly vedranportfolioEntities _vk = new vedranportfolioEntities();
		//
		// GET: /Portfolio/

		public ActionResult Index()
		{
			var portfolios = _vk.Article.Where(p => p.Type == (int)ArticleTypes.Portfolio && p.PublishDate <= DateTime.Now).OrderByDescending(p=>p.PublishDate);

			if (Request.IsAjaxRequest())
			{
				return PartialView("Index", portfolios.ToList());
			}
			else
			{
				return View(portfolios.ToList());
			}
		}

		public ActionResult Details(string id)
		{
			Article portfolio = _vk.Article.Where(p=>p.Type == (int)ArticleTypes.Portfolio && p.wfTitle == id).FirstOrDefault();
			if (portfolio != null)
			{
				if (Request.IsAjaxRequest())
				{
					return PartialView(portfolio);
				}
				else 
				{
					return View(portfolio);
				}
			}

			return RedirectToAction("Index", "Portfolio");
		}

	}
}
